﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
                    xmlns:Behaviours="clr-namespace:MahApps.Metro.Behaviours">

    <ControlTemplate x:Key="HorizontalScrollBarTemplate"
                     TargetType="{x:Type ScrollBar}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" />
            </Grid.ColumnDefinitions>
            <RepeatButton IsEnabled="{TemplateBinding IsMouseOver}"
                          Command="ScrollBar.PageLeftCommand">
                <RepeatButton.Style>
                    <Style TargetType="{x:Type RepeatButton}">
                        <Setter Property="OverridesDefaultStyle"
                                Value="True" />
                        <Setter Property="Focusable"
                                Value="False" />
                        <Setter Property="IsTabStop"
                                Value="False" />
                        <Setter Property="Padding"
                                Value="0,0,0,0" />
                        <Setter Property="BorderThickness"
                                Value="0" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type RepeatButton}">
                                    <Border Background="{x:Null}"
                                            Height="18"
                                            Width="18"
                                            VerticalAlignment="Center">
                                        <Path Data=" M 8 15 L 8 3 L 2 9 Z"
                                              Fill="{DynamicResource BlackBrush}" />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </RepeatButton.Style>
            </RepeatButton>
            <RepeatButton IsEnabled="{TemplateBinding IsMouseOver}"
                          Command="ScrollBar.PageRightCommand"
                          Grid.Column="2">
                <RepeatButton.Style>
                    <Style TargetType="{x:Type RepeatButton}">
                        <Setter Property="OverridesDefaultStyle"
                                Value="True" />
                        <Setter Property="Focusable"
                                Value="False" />
                        <Setter Property="IsTabStop"
                                Value="False" />
                        <Setter Property="Padding"
                                Value="0,0,0,0" />
                        <Setter Property="BorderThickness"
                                Value="0" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type RepeatButton}">
                                    <Border Background="{x:Null}"
                                            Height="18"
                                            Width="18"
                                            VerticalAlignment="Center">
                                        <Path Data=" M 9 15 L 9 3 L 15 9 Z"
                                              Fill="{DynamicResource BlackBrush}" />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </RepeatButton.Style>
            </RepeatButton>
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="VerticalScrollBarTemplate"
                     TargetType="{x:Type ScrollBar}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}" />
                <RowDefinition Height="*" />
                <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}" />
            </Grid.RowDefinitions>
            <RepeatButton IsEnabled="{TemplateBinding IsMouseOver}"
                          Command="ScrollBar.PageUpCommand">
                <RepeatButton.Style>
                    <Style TargetType="{x:Type RepeatButton}">
                        <Setter Property="OverridesDefaultStyle"
                                Value="True" />
                        <Setter Property="Focusable"
                                Value="False" />
                        <Setter Property="IsTabStop"
                                Value="False" />
                        <Setter Property="Padding"
                                Value="0,0,0,0" />
                        <Setter Property="BorderThickness"
                                Value="0" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type RepeatButton}">
                                    <Border Background="{x:Null}"
                                            Height="18"
                                            Width="18"
                                            HorizontalAlignment="Center">
                                        <Path Data=" M 2 9 L 14 9 L 8 3 Z"
                                              Fill="{DynamicResource BlackBrush}" />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </RepeatButton.Style>
            </RepeatButton>
            <RepeatButton IsEnabled="{TemplateBinding IsMouseOver}"
                          Command="ScrollBar.PageDownCommand"
                          Grid.Row="2">
                <RepeatButton.Style>
                    <Style TargetType="{x:Type RepeatButton}">
                        <Setter Property="OverridesDefaultStyle"
                                Value="True" />
                        <Setter Property="Focusable"
                                Value="False" />
                        <Setter Property="IsTabStop"
                                Value="False" />
                        <Setter Property="Padding"
                                Value="0,0,0,0" />
                        <Setter Property="BorderThickness"
                                Value="0" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type RepeatButton}">
                                    <Border Background="{x:Null}"
                                            Height="18"
                                            Width="18"
                                            HorizontalAlignment="Center">
                                        <Path Data=" M 2 10 L 14 10 L 8 16 Z"
                                              Fill="{DynamicResource BlackBrush}" />
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </RepeatButton.Style>
            </RepeatButton>
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="ScrollViewerTemplate"
                     TargetType="{x:Type ScrollViewer}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ScrollBar x:Name="PART_HorizontalScrollBar"
                       Height="14"
                       Cursor="Arrow"
                       Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                       Grid.Column="0"
                       Grid.Row="0"
                       Orientation="Horizontal"
                       ViewportSize="{TemplateBinding ViewportWidth}"
                       Maximum="{TemplateBinding ScrollableWidth}"
                       Minimum="0"
                       Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                       AutomationProperties.AutomationId="HorizontalScrollBar"
                       Template="{DynamicResource HorizontalScrollBarTemplate}" />
            <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                    VerticalAlignment="Center"
                                    Margin="15 2 15 2"
                                    Content="{TemplateBinding Content}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    Grid.Column="0"
                                    Grid.Row="0"
                                    CanContentScroll="{TemplateBinding CanContentScroll}"
                                    CanHorizontallyScroll="False"
                                    CanVerticallyScroll="False" />
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="VerticalScrollViewerTemplate"
                     TargetType="{x:Type ScrollViewer}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ScrollBar x:Name="PART_VerticalScrollBar"
                       Width="14"
                       Cursor="Arrow"
                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                       Grid.Column="0"
                       Grid.Row="0"
                       Orientation="Vertical"
                       ViewportSize="{TemplateBinding ViewportHeight}"
                       Maximum="{TemplateBinding ScrollableHeight}"
                       Minimum="0"
                       Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                       AutomationProperties.AutomationId="VerticalScrollBar"
                       Template="{DynamicResource VerticalScrollBarTemplate}" />
            <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                    HorizontalAlignment="Center"
                                    Margin="2 14 2 14"
                                    Content="{TemplateBinding Content}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    Grid.Column="0"
                                    Grid.Row="0"
                                    CanContentScroll="{TemplateBinding CanContentScroll}"
                                    CanHorizontallyScroll="False"
                                    CanVerticallyScroll="False" />
        </Grid>
    </ControlTemplate>

    <Style TargetType="{x:Type TabControl}">
        <Setter Property="Controls:ControlsHelper.Transition"
                Value="Left" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid KeyboardNavigation.TabNavigation="Local">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="ColumnDefinition0" />
                            <ColumnDefinition x:Name="ColumnDefinition1"
                                              Width="0" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition x:Name="RowDefinition0"
                                           Height="Auto" />
                            <RowDefinition x:Name="RowDefinition1"
                                           Height="*" />
                        </Grid.RowDefinitions>
                        <ScrollViewer x:Name="HeaderPanelScroll"
                                      VerticalScrollBarVisibility="Disabled"
                                      HorizontalScrollBarVisibility="Auto"
                                      Template="{StaticResource ScrollViewerTemplate}">
                            <TabPanel x:Name="HeaderPanel"
                                      IsItemsHost="True"
                                      Panel.ZIndex="1"
                                      Grid.Column="0"
                                      Grid.Row="0"
                                      KeyboardNavigation.TabIndex="1" />
                        </ScrollViewer>
                        <Controls:TransitioningContentControl x:Name="ContentPanel"
                                                              Transition="{TemplateBinding Controls:ControlsHelper.Transition}"
                                                              Behaviours:ReloadBehavior.OnSelectedTabChanged="True"
                                                              RestartTransitionOnContentChange="True"
                                                              Grid.Column="0"
                                                              Grid.Row="1">
                            <ContentPresenter x:Name="PART_SelectedContentHost"
                                              ContentTemplate="{TemplateBinding SelectedContentTemplate}"
                                              Content="{TemplateBinding SelectedContent}"
                                              ContentStringFormat="{TemplateBinding SelectedContentStringFormat}"
                                              ContentSource="SelectedContent"
                                              Margin="{TemplateBinding Padding}"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Controls:TransitioningContentControl>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="TabStripPlacement"
                                 Value="Bottom">
                            <Setter Property="Grid.Row"
                                    TargetName="HeaderPanelScroll"
                                    Value="1" />
                            <Setter Property="Grid.Row"
                                    TargetName="ContentPanel"
                                    Value="0" />
                            <Setter Property="Height"
                                    TargetName="RowDefinition0"
                                    Value="*" />
                            <Setter Property="Height"
                                    TargetName="RowDefinition1"
                                    Value="Auto" />
                            <Setter Property="Margin"
                                    TargetName="HeaderPanelScroll"
                                    Value="2,0,2,2" />
                        </Trigger>
                        <Trigger Property="TabStripPlacement"
                                 Value="Left">
                            <Setter Property="Controls:ControlsHelper.Transition"
                                    Value="Right" />
                            <Setter Property="Grid.Row"
                                    TargetName="HeaderPanelScroll"
                                    Value="0" />
                            <Setter Property="Grid.Row"
                                    TargetName="ContentPanel"
                                    Value="0" />
                            <Setter Property="Grid.Column"
                                    TargetName="HeaderPanelScroll"
                                    Value="0" />
                            <Setter Property="Grid.Column"
                                    TargetName="ContentPanel"
                                    Value="1" />
                            <Setter Property="Width"
                                    TargetName="ColumnDefinition0"
                                    Value="Auto" />
                            <Setter Property="Width"
                                    TargetName="ColumnDefinition1"
                                    Value="*" />
                            <Setter Property="Height"
                                    TargetName="RowDefinition0"
                                    Value="*" />
                            <Setter Property="Height"
                                    TargetName="RowDefinition1"
                                    Value="0" />
                            <Setter Property="Margin"
                                    TargetName="HeaderPanelScroll"
                                    Value="2,2,0,2" />
                            <Setter Property="VerticalScrollBarVisibility"
                                    TargetName="HeaderPanelScroll"
                                    Value="Auto" />
                            <Setter Property="HorizontalScrollBarVisibility"
                                    TargetName="HeaderPanelScroll"
                                    Value="Disabled" />
                            <Setter Property="Template"
                                    TargetName="HeaderPanelScroll"
                                    Value="{DynamicResource VerticalScrollViewerTemplate}" />
                        </Trigger>
                        <Trigger Property="TabStripPlacement"
                                 Value="Right">
                            <Setter Property="Grid.Row"
                                    TargetName="HeaderPanelScroll"
                                    Value="0" />
                            <Setter Property="Grid.Row"
                                    TargetName="ContentPanel"
                                    Value="0" />
                            <Setter Property="Grid.Column"
                                    TargetName="HeaderPanelScroll"
                                    Value="1" />
                            <Setter Property="Grid.Column"
                                    TargetName="ContentPanel"
                                    Value="0" />
                            <Setter Property="Width"
                                    TargetName="ColumnDefinition0"
                                    Value="*" />
                            <Setter Property="Width"
                                    TargetName="ColumnDefinition1"
                                    Value="Auto" />
                            <Setter Property="Height"
                                    TargetName="RowDefinition0"
                                    Value="*" />
                            <Setter Property="Height"
                                    TargetName="RowDefinition1"
                                    Value="0" />
                            <Setter Property="Margin"
                                    TargetName="HeaderPanelScroll"
                                    Value="0,2,2,2" />
                            <Setter Property="VerticalScrollBarVisibility"
                                    TargetName="HeaderPanelScroll"
                                    Value="Auto" />
                            <Setter Property="HorizontalScrollBarVisibility"
                                    TargetName="HeaderPanelScroll"
                                    Value="Disabled" />
                            <Setter Property="Template"
                                    TargetName="HeaderPanelScroll"
                                    Value="{DynamicResource VerticalScrollViewerTemplate}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>